package com.ssm.crud.controller;

import java.util.ArrayList;
import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

import com.ssm.crud.bean.Msg;
import com.ssm.crud.service.EmployeeService;

@Controller
public class EmployeeDeleteController {

	@Autowired
	private EmployeeService employeeService;
	
	@RequestMapping(value="/empdelete/{ids}",method=RequestMethod.DELETE)
	@ResponseBody
	public Msg empDelete(@PathVariable("ids")String ids) {
		
		if(ids.contains("-")) {
			List<Integer> del_ids=new ArrayList<>();
			String[] str_ids = ids.split("-");
			for(String string:str_ids) {
				del_ids.add(Integer.parseInt(string));
			}
			employeeService.deleteBatch(del_ids);
 		}else {
 			Integer id=Integer.parseInt(ids);
 			employeeService.deleteByPrimaryKey(id);
 		}
		return Msg.success();
	}
	
}
